package com.example.photoview;

import com.example.photoview.ImageBox;
import com.example.photoview.ImageModel;
import javafx.scene.effect.DropShadow;

import java.util.ArrayList;

public class SelectionModel {
    //暂存选中的缩略图
    public static ArrayList<ImageBox> selection=new ArrayList<>();
    //存放选中图片本身
    public static ArrayList<ImageModel> imageModels =new ArrayList<>();

    /**
     * add函数
     */
    public static void add(ImageBox node){
        DropShadow ds=new DropShadow();
        ds.setHeight(4);
        ds.setWidth(4);
        node.getImageView2().setTranslateY(node.getImageView2().getTranslateY()-8);
        selection.add(node);
        imageModels.add(node.getImageModel());
        logSeletion();
        //控制
    }

    /**
     * move函数
     *
     */
    public static void remove(ImageBox node){
        DropShadow ds=new DropShadow();
        ds.setHeight(0);
        ds.setWidth(0);
        node.getImageView2().setTranslateY(node.getImageView2().getTranslateY()+8);
        selection.remove(node);
        imageModels.remove(node.getImageModel());
        logSeletion();
        //System.out.println("remove function work");
}
    public static void clear(){
        while(selection.isEmpty()==false){
//            selection.remove(node);
//            imageModels.remove(node.getImageModel());

            selection.iterator().next().getCheckBox().setSelected(false);
            //selection.clear();
            logSeletion();
        }
}


//    private static boolean contains(ImageBox node) {
//        for (ImageBox ib : selection) {
//            if (ib.equals(node))
//                return true;
//        }
//        return false;
//    }

    public static ArrayList<ImageBox> getSelection() {
        return selection;
    }

    public static ArrayList<ImageModel> getImageModels() {
        return imageModels;
    }

    private static void logSeletion() {
        System.out.println("Items in list: " + selection);
    }
}
